﻿/*
 * 文件名称：
 * 程序员：wangyun
 * 创建时间：2008/07/03
 * 
 * 功能说明：内容呈现控件
 * 
 * 修改人员：
 * 
 * 修改日期：
 * 
 * 修改记录：
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common.WebHelper;

public partial class UserControls_ContentControl_CommonContent : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }

    /// <summary>
    /// 绑定数据
    /// </summary>
    private void BindData()
    {
        Whir.BLL.Whir_ModelForm modelFormModel = new Whir.BLL.Whir_ModelForm();
        string[] left = new string[] { };
        string fieldIDs = modelFormModel.GetFieldIDsAll(ModelFormID);

        DataTable dt = new DataTable();
        Whir.BLL.Whir_Field bll = new Whir.BLL.Whir_Field();
        Repeater1.DataSource = bll.GetList("FieldID in (" + fieldIDs + ") AND ModelID = " + ModelID).Tables[0];
        Repeater1.DataBind();
    }

    #region 属性
    /// <summary>
    /// 功能模块 ID
    /// </summary>
    public int ModelID
    {
        get
        {
            int _modelID = 0;
            if (ViewState["ModelID"] != null)
                _modelID = int.Parse(ViewState["ModelID"].ToString());
            return _modelID;
        }
        set { ViewState["ModelID"] = value; }
    }

    /// <summary>
    /// 功能模块的表单 ID
    /// </summary>
    public int ModelFormID
    {
        get
        {
            int _modelFormID = 0;
            if (ViewState["ModelFormID"] != null)
                _modelFormID = int.Parse(ViewState["ModelFormID"].ToString());
            return _modelFormID;
        }
        set { ViewState["ModelFormID"] = value; }
    }

    /// <summary>
    /// 获取用户控件中的 Repeater 控件
    /// </summary>
    public Repeater Repeater
    {
        get
        {
            return this.Repeater1;
        }
    }
    #endregion


    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item)
        {
            HtmlTableRow tr = (HtmlTableRow)e.Item.FindControl("formTR");

            if (tr != null)
            {
                DataRowView dv = (DataRowView)e.Item.DataItem;

                FieldType type = (FieldType)int.Parse(dv["fieldType"].ToString());

                switch(type)
                {
                    case FieldType.None:
                        tr.Style.Add("display", "none");
                        break;
                    case FieldType.DateTimeType:
                        if (dv["DefaultValue"].ToString() == "1")
                        {
                            tr.Style.Add("display", "none");
                        }
                        break;
                    default:
                        break;
                }
            }
        }
    }
}
